﻿using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NbMeterServices.Entity
{
    public class MrMeterJk
    {
        /// <summary>
        /// 版本
        /// </summary>
        [SugarColumn(ColumnName = "Version", ColumnDescription = "版本", Length = 10)]
        public string? Version { get; set; }

        /// <summary>
        /// 水表序列号
        /// </summary>
        [SugarColumn(ColumnName = "MeterNo", ColumnDescription = "水表序列号", Length = 20)]
        public string? No { get; set; }

        /// <summary>
        /// ICCID
        /// </summary>
        [SugarColumn(ColumnName = "ICCID", ColumnDescription = "ICCID", Length = 20)]
        public string? ICCID { get; set; }

        /// <summary>
        /// 动作
        /// </summary>
        [SugarColumn(ColumnName = "Flag", ColumnDescription = "动作")]
        public int? Flag { get; set; }


        [SugarColumn(IsIgnore = true)]
        public List<Act> Act { get; set; }

        /// <summary>
        /// 温度
        /// </summary>
        [SugarColumn(ColumnName = "Temp", ColumnDescription = "温度", Length = 4, DecimalDigits = 2)]
        public decimal? Temp { get; set; }

        /// <summary>
        /// CSQ
        /// </summary>
        [SugarColumn(ColumnName = "CSQ", ColumnDescription = "CSQ")]
        public int? CSQ { get; set; }

        /// <summary>
        /// 电池电压
        /// </summary>
        [SugarColumn(ColumnName = "Vbat", ColumnDescription = "电池电压", Length = 4, DecimalDigits = 2)]
        public decimal? Vbat { get; set; }

        /// <summary>
        /// 累计水量
        /// </summary>
        [SugarColumn(ColumnName = "Used", ColumnDescription = "累计水量", Length = 8, DecimalDigits = 3)]
        public decimal? Used { get; set; }

        /// <summary>
        /// 累计进水
        /// </summary>
        [SugarColumn(ColumnName = "Inflow", ColumnDescription = "累计进水", Length = 8, DecimalDigits = 3)]
        public decimal? Inflow { get; set; }

        /// <summary>
        /// 累计回水
        /// </summary>
        [SugarColumn(ColumnName = "Back", ColumnDescription = "累计回水", Length = 8, DecimalDigits = 3)]
        public decimal? Back { get; set; }

        /// <summary>
        /// 阀门状态
        /// </summary>
        [SugarColumn(ColumnName = "Valve", ColumnDescription = "阀门状态")]
        public Int16? Valve { get; set; }

        /// <summary>
        /// 错误代码
        /// </summary>
        [SugarColumn(ColumnName = "Error", ColumnDescription = "错误代码")]
        public int? Error { get; set; }

        /// <summary>
        /// 上传时间
        /// </summary>
        [SugarColumn(ColumnName = "Time", ColumnDescription = "上传时间", Length = 18)]
        public string? Time { get; set; }

        /// <summary>
        /// 第一次时间
        /// </summary>
        [SugarColumn(ColumnName = "FirstTime", ColumnDescription = "第一次时间", Length = 18)]
        public string? FirstTime { get; set; }

        /// <summary>
        /// 数据时间
        /// </summary>
        [SugarColumn(ColumnName = "DataTime", ColumnDescription = "数据时间")]
        public DateTime? DataTime { get; set; }

        /// <summary>
        /// 可用水量
        /// </summary>
        [SugarColumn(ColumnName = "Balance", ColumnDescription = "可用水量", Length = 8, DecimalDigits = 3)]
        public decimal? Balance { get; set; }

        /// <summary>
        /// 错误信息
        /// </summary>
        [SugarColumn(ColumnName = "ErrorInfo", ColumnDescription = "错误信息", Length = 50)]
        public string? ErrorInfo { get; set; }

        /// <summary>
        /// 进水阀状态
        /// </summary>
        [SugarColumn(ColumnName = "ValveIn", ColumnDescription = "进水阀状态")]
        public byte? ValveIn { get; set; }

        /// <summary>
        /// 回水阀状态
        /// </summary>
        [SugarColumn(ColumnName = "ValveBack", ColumnDescription = "回水阀状态")]
        public byte? ValveBack { get; set; }

        /// <summary>
        /// 上报周期
        /// </summary>
        [SugarColumn(ColumnName = "Cyc", ColumnDescription = "上报周期")]
        public int? Cyc { get; set; }


        public void Process()
        {
            if(Valve != null)
            {
                ValveIn = (byte)(Valve & 0xFF);
                ValveBack =  (byte)(Valve >> 8);
            }
        }

    }
}
